$KCODE = 'U'

require 'rubygems'
require 'dm-core'
require 'dm-timestamps'

DataMapper.setup(:default, "sqlite3:///#{Dir.pwd}/db/verynotes.db")

module Verynotes
  class Note
    include DataMapper::Resource
    property :id, Serial
    property :title, String
    property :body, Text
    property :deleted, Boolean, :default => false
    property :hidden, Boolean, :default => false
    property :created_at, DateTime
    property :updated_at, DateTime

    has n, :tags, :through => Resource, :class_name => 'Verynotes::Tag'
  end

  class Tag
    include DataMapper::Resource
    property :id, Serial
    property :name, String

    has n, :notes, :through => Resource, :class_name => 'Verynotes::Note'
  end

  def find_notes_by_tag(id, deleted = false, hidden = false)
    tag = Tag.get(id)
    tag.notes(
      :order => [:created_at.desc],
      :conditions => ['deleted = ? and hidden = ?', deleted, hidden]
    )
  end

  def test
    print 1
  end
end

#DataMapper.auto_migrate!

